//
//  HomeConvenientCollectionViewCell.m
//  CommunitySupermarketProiect
//
//  Created by 吕惠卿 on 2017/10/23.
//  Copyright © 2017年 吕惠卿. All rights reserved.
//

#import "HomeConvenientCollectionViewCell.h"

@implementation HomeConvenientCollectionViewCell
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}
-(void)creatUI{
    _xianmoneyLab = [[UILabel alloc]init];
    _xianmoneyLab.textColor = [UIColor redColor];
    _xianmoneyLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_xianmoneyLab];
    [_xianmoneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-8);
        make.bottom.equalTo(self.mas_bottom).with.offset(-4);
        make.width.mas_equalTo(WIDTH/2);
        make.height.mas_equalTo(20);
    }];
    
    

    _oldmoneyLab = [[UILabel alloc]init];
    _oldmoneyLab.font = [UIFont systemFontOfSize:15.0];
    _oldmoneyLab.textColor = [UIColor lightGrayColor];
    _oldmoneyLab.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_oldmoneyLab];
    [_oldmoneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(8);
        make.bottom.equalTo(self.mas_bottom).with.offset(-4);
        make.width.mas_equalTo(WIDTH/2);
        make.height.mas_equalTo(20);
    }];
    NSString *oldPrice = @"¥12345";
    NSUInteger length = [oldPrice length];
    //从这里开始就是设置富文本的属性
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];
    //下面开始是设置线条的风格：
    //第一个参数addAttribute:是设置要中线（删除线）还是下划线。
    //NSStrikethroughStyleAttributeName：这种是从文本中间穿过，也就是删除线。
    //NSUnderlineStyleAttributeName：这种是下划线。
    
    //第二个参数value：是设置线条的风格：虚线，实现，点线......
    //第二参数需要同时设置Pattern和style才能让线条显示。
    
    //第三个参数range:是设置线条的长度，切记，不能超过字符串的长度，否则会报错。
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)  range:NSMakeRange(0, length)];
    
    //下列是设置线条的颜色
    //第一个参数就是选择设置中线的颜色还是下划线的颜色，如果上面选择的是中线，这里就要选择中线，否则颜色设置不上去。
    //第二个参数很简单，就是颜色而已。
    //第三个参数：同上。
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length)];
    
    [_oldmoneyLab setAttributedText:attri];

    
    
    _nameLab = [[UILabel alloc]init];
    _nameLab.font = [UIFont systemFontOfSize:15.0];
    _nameLab.numberOfLines = 0;
    _nameLab.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(8);
        make.right.equalTo(self.mas_right).with.offset(-8);
        make.bottom.equalTo(_xianmoneyLab.mas_top).with.offset(0);
        make.height.mas_equalTo(40);
    }];
    
    _imageView = [[UIImageView alloc]init];
    _imageView.backgroundColor = LineColor;
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(4);
        make.left.equalTo(self.contentView.mas_left).with.offset(3);
        make.right.equalTo(self.contentView.mas_right).with.offset(-3);
        make.bottom.equalTo(_nameLab.mas_top).with.offset(-3);
    }];
    
    
    
}
@end
